package com.cs410.collabwriting.junit.main;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;

import com.cs410.collabwriting.main.TagManager;
import com.cs410.collabwriting.main.User;
import com.cs410.collabwriting.main.UserManager;
import com.cs410.collabwriting.test.DatabaseUtility;
import com.cs410.collabwriting.tools.LogManager;

import junit.framework.Assert;

public class TagManagerTest {
    @Rule
    public TestName m_testName = new TestName();
    private static User test_user;
    
    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
        LogManager.logInfo("[JUnitTest] -- Starting JUnit Tests for StoryManager" );
        DatabaseUtility.DeleteAllTables();        
        Thread.sleep(1000);        
        DatabaseUtility.CreateAllTables();        
        Thread.sleep(1000);        
        DatabaseUtility.CreateAllTestingData();
        Thread.sleep(15000);
        
        test_user = UserManager.getInstance().addUser("test_user", "password", "email");
    }

    @AfterClass
    public static void tearDownAfterClass() throws Exception {
        LogManager.logInfo("[JUnitTest] -- Finished JUnit Tests for StoryManager" );
    }

    @Before
    public void setUp() throws Exception {
        LogManager.logInfo("[JUnitTest] -- Starting Test : " + m_testName.getMethodName() );
    }

    @After
    public void tearDown() throws Exception {
        LogManager.logInfo("[JUnitTest] -- Finished Test : " + m_testName.getMethodName() );
    }
    
    @Test
    public void updateTagsTest() {
        String[] tags = {"FANTASY"};
        Assert.assertTrue(TagManager.getInstance().updateTags(2, test_user.getUserID(), tags));
    }
}
